

layer.config({
  skin: 'layer-ext-myskin'
});


AlertView = {
	maxTimeout:10000*1000,
	CreateGameHtml: {
		getHtml: function(data) {
			if(typeof data !="object"){
				data = {};
				data.width = "300";
				data.width = "100"
				data.func = "AlertView.delegate.submitClick();";
			}else{
			}
			
			var html = template("createHtmlTmp", data);
			return html;
		},
		getButton: function() {
			return $(".layui-layer .CreateGameHtml .btn");
		},
		getInput: function() {
			return $(".layui-layer .CreateGameHtml input");
		},
		init: function(delegate) {
			var btn = AlertView.CreateGameHtml.getButton();
			btn.on("click", delegate.submitClick);
		}
	},
	ApplyGameHtml: {
		getHtml: function(data) {
			var html = template("ApplyGameHtmlTmp", data);
			return html;
		},
		getButton: function() {
			return $(".layui-layer .ApplyGameHtml .btn");
		},
		getAddrInput: function() {
			var addrInput = $(".layui-layer .ApplyGameHtml input.hashId");
			return addrInput;
		},
		getValueInput: function() {
			return $(".layui-layer .ApplyGameHtml input.value");
		},
		init: function(delegate) {
			AlertView.delegate = delegate;
		}
	},
	SubmitChoiceHtml: {
		getHtml: function() {
			var html = $("#SubmitChoiceHtml").html();
			return html;
		},
		getButton: function() {
			return $(".layui-layer .SubmitChoiceHtml .btn");
		},
		getInput: function() {
			return $(".layui-layer .SubmitChoiceHtml input");
		},
		getSelecter: function() {
			return $(".layui-layer .SubmitChoiceHtml select");
		},
		init: function(delegate) {
			var btn = AlertView.SubmitChoiceHtml.getButton();
			btn.on("click", delegate.submitClick);

		}
	},
	layer: {
		load: function(title) {
//			$(".notify_loading .title").html(title);
//			var notify_loading = $(".notify_loading");
//			return notify_loading;
			var data  = {
				title:title
			};
			var html =  template("notifyLoading",data);
			return html;
		},
		layerDefaultOpt: function(title) {
			var opt = {
				type: 1,
				skin: 'layer-ext-myskin', //样式类名
				closeBtn: 0, //不显示关闭按钮
				anim: 2,
				title: [title, ],
				shadeClose: true, //开启点击遮罩关闭
				btnAlign: 'c',
				area: ['300', '200'],
				offset: '200px',
				
			};
			return opt;
		},
		msg:function(msg){
			var index =  layer.msg(msg,{
				offset: '200px'
			});
			setTimeout(function(index){
				if($("#layui-layer"+index).length > 1){
					layer.close(index);
					AlertView.layer.alert("错误","等待已经超时："+AlertView.maxTimeout/1000+"s");
				}
			},AlertView.maxTimeout,index);
			return index;
		},
		loading: function(title) {
			layer.closeAll();
			var opt = AlertView.layer.layerDefaultOpt("");
			opt.content = AlertView.layer.load(title);
			opt.title = false;
			opt.shadeClose = false; //关闭点击遮罩关闭
			var index = layer.open(opt);
			
			setTimeout(function(index){
				if($("#layui-layer"+index).length > 1){
					layer.close(index);
					AlertView.layer.alert("错误","等待已经超时："+AlertView.maxTimeout/1000+"s");
				}
			},AlertView.maxTimeout,index);
			return index;
		},
		alert: function(title, msg, option) {
			layer.closeAll();
			var opt = AlertView.layer.layerDefaultOpt(title);
			opt.btn = ["OK"];
			if(msg.length > 100){
			}
			var str = JSON.stringify(msg);
			if(typeof str =="undefined"){
				str = "";
			}
			opt.content = str.replace("\"","").replace("\"","");
			if(typeof option != "undefined") {
				for(var key in option) {
					opt[key] = option[key];
				}
			}
			opt.yes = function() {
				layer.closeAll();
			};
			var index = layer.open(opt);
			
			setTimeout(function(index){
				if($("#layui-layer"+index).length > 1){
					layer.close(index);
					AlertView.layer.alert("错误","等待已经超时："+AlertView.maxTimeout/1000+"s");
				}
			},AlertView.maxTimeout,index);
			return index;
		},
		open: function(title, content, success, option) {
			layer.closeAll();
			var opt = AlertView.layer.layerDefaultOpt(title);
			opt.success = success
			opt.content = content;

			if(typeof option != "undefined") {
				for(var key in option) {
					opt[key] = option[key];
				}
			}
			var index = layer.open(opt);
			setTimeout(function(index){
				if($("#layui-layer"+index).length > 1){
					layer.close(index);
					AlertView.layer.alert("错误","等待已经超时："+AlertView.maxTimeout/1000+"s");
				}
			},AlertView.maxTimeout,index);
			
			return index;
		}
	}

}